#include "mprpcapplication.h"
#include <iostream>
#include <string>
#include <unistd.h>
#include "mprpcconfig.h"
MprpcConfig MrpcApplication::m_config;
MrpcApplication& MrpcApplication::getInstance()
{
    static MrpcApplication app;
    return app;
}
void MrpcApplication::Init(int argc,char** argv)
{
    if(argc<2)
    {
        std::cout<<"invalid arguments\n";
        exit(EXIT_FAILURE);
    }
    int c=0;
    std::string config_file;
    while((c=getopt(argc,argv,"i:"))!=-1)
    {
        switch(c)
        {
        case 'i':
            config_file=optarg;
            break;
        case '?':
            std::cout<<"invalid args\n";
            exit(EXIT_FAILURE);
        case ':':
            std::cout<<"need <configfile>\n";
            exit(EXIT_FAILURE);
        default:
            break;
        }
    }
    //config file
    m_config.LoadConfigFile(config_file.c_str());
    std::cout<<"rpcserverip:"<<m_config.Load("rpcserverip")<<std::endl;
    std::cout<<"rpcserverport:"<<m_config.Load("rpcserverport")<<std::endl;
}